Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

329
Visualizações
How to programmatically click on a button and after a particular time in Javascript and jQuery | Bypass popup blocking in web Browsers

I was developing an application that programmatically shows a popup after 5 seconds, but i found out that web browsers like firefox, chrome, internet explorer, etc. were blocking the popup.

Popup blocking In the past, evil sites abused popups a lot. A bad page could open tons of popup windows with ads. So now most browsers try to block popups and protect the user.

Most browsers block popups if they are called outside of user-triggered event handlers like onclick

By default modern web browsers block popups triggered by a function or code. But does not block popups triggered by clicking on buttons.

// popup blocked
window.open('https://javascript.info');

// popup allowed
button.onclick = () => {
  window.open('https://javascript.info');
};

So i had to bypass their blocking policy by programmatically clicking on the button after 5 seconds to still initiate the same popup.

So i decided to post this as a question and also answer it by myself for those that might be facing the same issue.

Step 1. Create a button, give it and ID and pass a function name on the onClick

<button id="buttonID" onclick="trigerPopup()"></button> 

Step 2 Create trigerPopup function

function trigerPopup(){
        alert("Hello I am poping up after 5 seconds");
        //your code goes here
}

Step 3 After 5 seconds, programmatically clicked on button

    window.setTimeout(function () {

        //this will trigger a click on the button
        const buttonID = document.getElementById('buttonID').click();


   }, 5000);

Thanks guys

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Step 1. Create a button, give it and ID and pass a function name on the onClick

<button id="buttonID" onclick="trigerPopup()"></button> 

Step 2 Create trigerPopup function

function trigerPopup(){
        alert("Hello I am poping up after 5 seconds");
        //your code goes here
}

Step 3 After 5 seconds, programmatically clicked on button

    window.setTimeout(function () {

        //this will trigger a click on the button
        const buttonID = document.getElementById('buttonID').click();


   }, 5000);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda